{{template "member/top.html" .}}
<div class="m-b-md"><h3 class="m-b-none">{{msg . "Posts"}}</h3></div>
<style>
.url-title {
	width: 260px;
}
</style>
<section class="panel panel-default">
	<div class="row wrapper">
		<div class="col-sm-5 m-b-xs">
		</div>
		<div class="col-sm-4 m-b-xs">
		</div>
		<div class="col-sm-3">
			<div class="input-group search-group">
				<input type="text" class="input-sm form-control" placeholder="{{msg . "title"}}" id="keywords" value="{{.keywords}}" />
				<span class="input-group-btn">
					<button class="btn btn-sm btn-default" type="button" data-url="/member/blog/index">{{leaMsg $ "Search"}}</button>
				</span>
			</div>
		</div>
	</div>
	<div class="table-responsive">
		<table class="table table-striped b-t b-light">
			<thead>
				<tr>
					{{$url := urlConcat "/member/blog/index" "keywords" .keywords}}
					<th style="width: 300px"
					{{sorterTh $url "title" .sorter}}
					>
						Title	
						<span class="th-sort">
							<i class="fa fa-sort-down"></i>
							<i class="fa fa-sort-up"></i>
							<i class="fa fa-sort"></i>
						</span>
					</th>
					
					<th
					style="width: 300px"
					{{sorterTh $url "urlTitle" .sorter}}
					>
						{{msg $ "permanentLink"}}
						<span class="th-sort">
							<i class="fa fa-sort-down"></i>
							<i class="fa fa-sort-up"></i>
							<i class="fa fa-sort"></i>
						</span>
					</th>
					<th
					{{sorterTh $url "publicTime" .sorter}}
					>
						{{msg . "publicTime"}}
						<span class="th-sort">
							<i class="fa fa-sort-down"></i>
							<i class="fa fa-sort-up"></i>
							<i class="fa fa-sort"></i>
						</span>
					</th>
					
					<th
					{{sorterTh $url "updatedTime" .sorter}}
					>
						{{msg . "updatedTime"}}
						<span class="th-sort">
							<i class="fa fa-sort-down"></i>
							<i class="fa fa-sort-up"></i>
							<i class="fa fa-sort"></i>
						</span>
					</th>
					<th
					{{sorterTh $url "createdTime" .sorter}}
					>
						{{msg . "createdTime"}}
						<span class="th-sort">
							<i class="fa fa-sort-down"></i>
							<i class="fa fa-sort-up"></i>
							<i class="fa fa-sort"></i>
						</span>
					</th>
					<th width="30">
					</th>
				</tr>
			</thead>
			<tbody>
				{{range .blogs}}
				
				{{if .UrlTitle}}
					{{set $ "urlTitle" (decodeUrlValue .UrlTitle)}}
				{{else}}
					{{set $ "urlTitle" .NoteId.Hex}}
				{{end}}
				<tr>
					<td>
						<a href="{{$.userAndBlog.PostUrl}}/{{$.urlTitle}}" class="post" target="_blank">{{.Title}}</a>
					</td>
					
					<td>
						/post/
						<input type="text" data-id="{{.NoteId.Hex}}" class="url-title" value="{{$.urlTitle}}"/>
					</td>
						
					<td>
						{{.PublicTime|datetime}}
					</td>
						
					<td>
						{{.UpdatedTime|datetime}}
					</td>
					<td>
						{{.CreatedTime|datetime}}
					</td>
					<td>
						
						<a 
						{{if .HasSelfDefined}}
							title="{{msg $ "hasSelfDefined"}}"
							class="btn btn-sm btn-success"
						{{else}}
							title="{{msg $ "noSelfDefined"}}"
							class="btn btn-sm btn-default"
						{{end}}
						href="/member/blog/updateBlogAbstract?noteId={{.NoteId.Hex}}">{{msg $ "setAbstract"}}</a>
					</td>
				</tr>
				{{end}}
			</tbody>
		</table>
	</div>
	<footer class="panel-footer">
		<div class="row">
			<div class="col-sm-4 hidden-xs">
			</div>
			<div class="col-sm-4 text-center">
				<small class="text-muted inline m-t-sm m-b-sm">
				</small>
			</div>
			<div class="col-sm-4 text-right text-center-xs">
				{{set . "url" (urlConcat "/member/blog/index" "sorter" .sorter "keywords" .keywords)}}
				{{template "member/blog/page.html" .}}
			</div>
		</div>
	</footer>
</section>
	
{{template "member/footer.html" .}}

<script>
$(function() {
	var postUrl="{{$.userAndBlog.PostUrl}}";
	$(".url-title").change(function(){
		var $t = $(this);
		var url = $t.val();
		var noteId = $t.data('id');
		ajaxPost("/member/blog/updateBlogUrlTitle", {noteId: noteId, urlTitle: url}, function(re){
			if(reIsOk(re)) {
				$t.val(re.Item);
				var $a = $t.closest("tr").find(".post");
				
				$a.attr("href", postUrl + "/" + encodeURI(re.Item));
			} else {
				art.alert(re.Msg || "error");
			}
		});
	});
});
</script>

{{template "member/end.html" .}}
